package mi.payment.ui.director;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import mi.payment.R;
import mi.payment.adapter.BaseListAdapter;
import mi.payment.db.dao.UserInfo;

/**
 * @author sunmi on 2017/1/8.
 */
class OperatorAdminAdapter extends BaseListAdapter<UserInfo> {

    private OperatorAdminOnClick operatorAdminOnClick;

    OperatorAdminAdapter(Context context, OperatorAdminOnClick operatorAdminOnClick) {
        super(context);
        this.operatorAdminOnClick = operatorAdminOnClick;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = View.inflate(getContext(), R.layout.item_operator_admin, null);
            viewHolder.edit = (ImageView) convertView.findViewById(R.id.img_edit);
            viewHolder.delete = (ImageView) convertView.findViewById(R.id.img_delete);
            viewHolder.num = (TextView) convertView.findViewById(R.id.txt_num);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        final UserInfo item = getItem(position);

        viewHolder.num.setText(item.getUId());

        viewHolder.edit.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                operatorAdminOnClick.editOnClick(item);
            }
        });

        viewHolder.delete.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                operatorAdminOnClick.deleteOnClick(item);
            }
        });

        return convertView;
    }

    private static class ViewHolder {
        private TextView num;
        private ImageView edit;
        private ImageView delete;
    }

}
